/*
 * 数据字典选项接口
 * @Description: jishupu-admin-template
 * @Author: 技术铺<jishupu@qq.com>
 * @Date: 2021-11-15
 */

import request from '@/utils/request'

/**
  * 列表
  * @param {Number} did 数据字典标识
  * @param {Object} params
  * @param {Object} extendConfig
  * @returns  new Promise
 */
export function index(did, params, extendConfig) {
  return request.get(`/v1/dictionary/${did}/dictionary-items`, { params, ...extendConfig })
}

/**
  * 添加
  * @param {Number} did 数据字典标识
  * @param {Object} params
  * @param {Object} extendConfig
  * @returns  new Promise
 */
export function store(did, params, extendConfig) {
  return request.post(`/v1/dictionary/${did}/dictionary-items`, params, extendConfig)
}

/**
  * 查看
  * @param {Number} did 数据字典标识
  * @param {Number} id 选项标识
  * @param {Object} extendConfig
  * @returns  new Promise
 */
export function show(did, id, extendConfig) {
  return request.get(`/v1/dictionary/${did}/dictionary-items/${id}`, extendConfig)
}

/**
 * 修改
 * @param {Number} did 数据字典标识
 * @param {Number} id 选项标识
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function update(did, id, params, extendConfig) {
  return request.put(`/v1/dictionary/${did}/dictionary-items/${id}`, params, extendConfig)
}

/**
 * 删除
 * @param {Number} did 数据字典标识
 * @param {Number | String} id  选项标识 例：数字1或字符串1,2,3
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function destory(did, id, extendConfig) {
  return request.delete(`/v1/dictionary/${did}/dictionary-items/${id}`, extendConfig)
}

/**
 * 更新状态
 * @param {Number} did 数据字典标识
 * @param {Number} id 选项标识
 * @param {Object} params 参数如： { status: 0 }
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateStatus(did, id, params, extendConfig) {
  return request.patch(`/v1/dictionary/${did}/dictionary-items/${id}/status`, params, extendConfig)
}

/**
 * 更新排序
 * @param {Number} did 数据字典标识
 * @param {Array} params 参数如：{sort: [{id: 7, sort: 2}, {id: 8, sort: 1}]}
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateSort(did, params, extendConfig) {
  return request.put(`/v1/dictionary/${did}/dictionary-items/sort`, params, extendConfig)
}

